<template>
	<view>
		<u-cell-group>
			 <u-cell-item  title="头像" :arrow="false" hover-class="cell-hover-calss" @click="toSetAvatar">
				 <view slot="right-icon">
					<view class="u-flex  u-col-center">
						<u-avatar mode="square" :src="vuex_userInfo.avatar" size="60"></u-avatar>
						<u-icon class="u-margin-left-10" name="arrow-right" color="#909399" size="28"></u-icon>
					</view>
				 </view>
			 </u-cell-item>
			 <u-cell-item title="昵称" :value="vuex_userInfo.name" @click="openUserNameModel()"></u-cell-item>
			 <u-modal v-model="userNameModel" title="修改昵称" show-cancel-button
						@confirm="comfirmUpdateUserName()" @cancel="cancelUpdateUserName()">
				<view class="slot-content">
				 	<u-field type="text" v-model="updatedUserName" label-width="10" label="" placeholder="请填写昵称"></u-field>
				</view>
			 </u-modal>
			 <u-cell-item title="账号" :value="vuex_userInfo.account"></u-cell-item>
			 <!-- <u-cell-item title="二维码名片"  @click="$u.route('/pages/my/qr-info')">
        <u-image slot="right-icon" src="/static/image/mycenter/myqrcode.png" width="30rpx" height="30rpx"></u-image>
      </u-cell-item> -->

			 <view  @click="sexSelectShow=true">
				 <u-cell-item title="性别" value="男" v-if="vuex_userInfo.gender==='man'"></u-cell-item>
				 <u-cell-item title="性别" value="女" v-else-if="vuex_userInfo.gender==='woman'"></u-cell-item>
				 <u-cell-item title="性别" value="保密" v-else></u-cell-item>
			 </view>
			 <u-select v-model="sexSelectShow" :list="sexOptions" @confirm="confirmUpdateSex"></u-select>
			
			 <u-cell-item  @click="openSignatureModel()"  title="个性签名" :value="vuex_userInfo.sign || '去设置'"></u-cell-item>


			 <u-modal v-model="signatureModel" title="设置个性签名" show-cancel-button 
			 						@confirm="comfirmUpdateSignature()" @cancel="cancelUpdateSignature()">
						<view class="slot-content">
							<u-field   	v-model="newSignature" label-width="10" label="" placeholder="请填写个性签名"></u-field>
						</view>
			 </u-modal>

			 <u-cell-item  @click="setCopy"  title="邀请码" :value="vuex_userInfo.invite_code"></u-cell-item>

		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressDetail:'',
				addressDetailModel:false,
				
				userAvatar:'',
				currentUser:{},
				userNameModel:false,
				updatedUserName:'',
				realNameModel:false,
				updatedRealName:'',
				chatNumberModel:false,
				updatedchatNumber:'',
				errorMessage:'',
				sexSelectShow:false,
				sexOptions:[
					{
						value: 'man',
						label: '男'
					},
					{
						value: 'woman',
						label: '女'
					},
          {
            value: 'unknow',
            label: '保密'
          }
				],
				addressPickerShow:false,
				signatureModel:false,
				newSignature:'',
				
			};
		},
		methods:{
      setCopy () {
        uni.setClipboardData({
          data: this.vuex_userInfo.invite_code,
          success: function () {
            uni.showToast({
              title: '复制成功',
              icon: 'none'
            })
          }
        })
      },
			toSetAvatar:function(){
				this.$u.route("/pages/my/setAvatar");
			},
			openUserNameModel:function(){
				this.userNameModel=true;
				this.updatedUserName=this.vuex_userInfo.name;
			},
			comfirmUpdateUserName:function(){
				if(this.updatedUserName.length<1){
					this.globalUtil.utilAlert("不能为空!");
					this.openUserNameModel();
				}else{
          this.$store.dispatch('vuex_userInfo', {
            name: this.updatedUserName
          })
				}
			},
			cancelUpdateUserName:function(){
				this.userNameModel=false;
			},
			openRealNameModel:function(){
				this.realNameModel=true;
				this.updatedRealName=this.currentUser.realName;
			},
			comfirmUpdateRealName:function(){
				if(this.updatedRealName.length<1){
					this.globalUtil.utilAlert("不能为空!");
					this.openRealNameModel();
				}else{
					this.currentUser.realName=this.updatedRealName;
					this.updateUserInfo();
				}
			},
			cancelUpdateRealName:function(){
				this.realNameModel=false;
			},
			
			onInputChatNumber:function(value){
				console.log("value",value);
				if(value.length>0){
					let reg = /[\u4e00-\u9fa5]+/g;
				    let chArr=value.match(reg);
					if(chArr!=null&&chArr.length>0){
						//this.globalUtil.utilAlert("不支持中文!");
						this.errorMessage="不支持中文!";
						return;
					}else{
						this.errorMessage="";
						return;
					}
				}
			},
			openChatNumberModel:function(){
				this.chatNumberModel=true;
				this.updatedchatNumber=this.currentUser.chatNumber;
			},
			comfirmUpdatechatNumber:function(){
				if(this.updatedchatNumber.length<1){
					this.globalUtil.utilAlert("不能为空!");
					this.openChatNumberModel();
				}else{
					this.currentUser.chatNumber=this.updatedchatNumber;
					this.updateUserInfo();
				}
			},
			cancelUpdatechatNumber:function(){
				this.chatNumberModel=false;
			},
			
			openSignatureModel:function(){
			   this.signatureModel=true;
			   this.newSignature=this.vuex_userInfo.sign;	   
			},
			
			comfirmUpdateSignature:function(){
				this.$store.dispatch('vuex_userInfo', {
          sign: this.newSignature
        })
			},
			cancelUpdateSignature:function(){
				 this.signatureModel=false;
				 this.newSignature=";"
			},
			
			confirmUpdateSex:function(e){
				this.$store.dispatch('vuex_userInfo', {
          gender: e[0].value
        })
			},
			//修改用户信息
			updateUserInfo (params) {
        this.$store.dispatch('vuex_userInfo', params)
			},
		
		   //选择地址
			comfirmUpdateAddress:function(obj){
				//console.log("obj",obj);
				this.currentUser.address=JSON.stringify(obj);
				this.addressDetailModel=true;
				//this.addressDetail="";
			},
			comfirmUpdateAddressDetail:function(){
				let addressStr=	this.currentUser.address;
				let addr=JSON.parse(addressStr);
				if(this.addressDetail.length>0){
				    addr.detail={"label":this.addressDetail};
				}
				this.currentUser.address=JSON.stringify(addr);
				this.updateUserInfo();
			},
			cancelUpdateAddressDetail:function(){
					this.addressDetailModel=false;
					this.updateUserInfo();
			},
			//解析地址
			parseAddress:function(address){
				let addressStr="设置"
				if(address!=null&&address.length>0){
					let addressObj= JSON.parse(address);
					let provice= addressObj.province.label;
					let city=addressObj.city.label;
					let area=addressObj.area.label;
					addressStr=provice+"-"+city+"-"+area;
					let detail=addressObj.detail;
					if(detail!=null&&detail!=undefined){
						this.addressDetail=detail.label;
					}
				}
				return addressStr;
			},
			setDefaultAddress:function(address){
				let addressObj= JSON.parse(address);
				let provice= addressObj.province.value;
				let city=addressObj.city.value;
				let area=addressObj.area.value;
				return [provice,city,area];
			},
		}
	}
</script>

<style lang="scss">
	.cell-hover-calss{
		background-color: rgb(235, 237, 238) !important;
	}
</style>
